package com.example.message2;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class MessageSQLiteHelper extends SQLiteOpenHelper{

	//CREATE  TABLE "main"."Contacts" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE , "name" VARCHAR, "address" VARCHAR, "cell" VARCHAR, "alt" VARCHAR, "email" VARCHAR, "comments" TEXT, "cat1" BOOL, "cat2" BOOL, "cat3" BOOL, "cat4" BOOL, "cat5" BOOL)
		public static final String TABLE_USERS = "users";
		public static final String COLUMN_ID = "id";
		public static final String COLUMN_LAST_READ = "lastreadid";
		
		public static final String TABLE_MESSAGES = "messages";
		public static final String COLUMN_MESSAGE_ID = "messageid";
		public static final String COLUMN_MESSAGE_SENDER = "sender";
		public static final String COLUMN_MESSAGE_RECEIVER = "receiver";
		public static final String COLUMN_MESSAGE_TEXT = "text";

		
		private static final String DATABASE_NAME = "mycontacts.db";
		private static final int DATABASE_VERSION = 1;
		
		private static final String DATABASE_CREATE = "CREATE TABLE " + TABLE_USERS + "(" + 
				COLUMN_ID + "INTEGER PRIMARY KEY," +
				COLUMN_LAST_READ+" INTEGER)";
		
		private static final String MESSAGES_DATABASE_CREATE = "CREATE TABLE " + TABLE_MESSAGES + "(" + 
				COLUMN_MESSAGE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
				COLUMN_MESSAGE_RECEIVER+" INTEGER,"+
				COLUMN_MESSAGE_SENDER + " INTEGER,"+
				COLUMN_MESSAGE_TEXT+" VARCHAR)";
		
		public MessageSQLiteHelper(Context context){
			super(context, DATABASE_NAME, null, DATABASE_VERSION);
		}
		
		 @Override
		 public void onCreate(SQLiteDatabase database) {
		    database.execSQL(DATABASE_CREATE);
		    database.execSQL(MESSAGES_DATABASE_CREATE);
		 }
		
		  @Override
		  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		    Log.w(MessageSQLiteHelper.class.getName(),
		        "Upgrading database from version " + oldVersion + " to "
		            + newVersion + ", which will destroy all old data");
		    db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
		    db.execSQL("DROP TABLE IF EXISTS " + TABLE_MESSAGES);
		    onCreate(db);
		  }
				
}
